﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-05-21-20:35
//  * @Description:
//  */

using Code.Core.CoreBaseClass;
using Code.GameLogic.Common.Component;
using QFramework;
using Unity.VisualScripting;
using UnityEngine;

namespace Code.GameLogic.BaseClass
{
    public abstract class AbsGameLogicController<BaseBo, AbsGameLogicManager> : BaseController,IWatchObject
    {
        public BaseBo bo;
        public AbsGameLogicManager manager;
        private IWatchObject _watchObjectImplementation;

        public override IArchitecture GetArchitecture()
        {
            return MainApp.Interface;
        }

        public abstract void InitGo(BaseBo bo);

        public TBaseComponent BindComponent<TController, TBaseComponent>(TController tController)
            where TController : AbsGameLogicController<BaseBo, AbsGameLogicManager>
            where TBaseComponent : AbsGameLogicComponent<TController>
        {
            var tBaseComponent = tController.AddComponent<TBaseComponent>();
            tBaseComponent.BindComponent(tController);
            return tBaseComponent;
        }


        #region 注视组件

        public float delayTime = 0.2f; // 触发延迟时间
        
        public virtual void Watch()
        {
            throw new System.NotImplementedException();
        }

        public virtual void Ignore()
        {
            throw new System.NotImplementedException();
        }

        public void IsWatch()
        {
            Vector3 mousePos = Input.mousePosition;
            mousePos.z = 10;
            Vector3 screenPos = Camera.main.ScreenToWorldPoint(mousePos);
            RaycastHit2D hit = Physics2D.Raycast(screenPos, Vector2.zero);
            
            if (hit)
            {
                if (hit.collider.gameObject==gameObject)
                {
                    delayTime -= Time.deltaTime;
                    if (delayTime<=0)
                    {
                        Watch();
                    }
                }
                else
                {
                    Ignore();
                    delayTime = 0.2f; // 重置延迟时间
                }
            }
            
        }
        
        

        

        #endregion
        
        
        
        
        
    }
}